/* 

source: [-4,1, 10, -1, -8, 3, 6, -9, 1]
result: [-4, -1,-8,-9,1,10,3,6,1]

*/

function exchange(nums) {
    let left = 0,
        right = nums.length - 1;
    while (left < right) {
        while (nums[left] < 0) left++;
        while (nums[right] > 0) right--;
        if (left < right) {
            let temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
        }
    }

    return nums;
}

console.log(exchange([-4, 1, 10, -1, -8, 3, 6, -9, 1, -1, -2, -3, -4]))